<?php
include_once('../config.php'); 
	session_start();
	LinkDataBase();
			
	$Array_DBTableName = DBTableNameGet($_SESSION['ID'], $_POST['year'], $_POST['season'], $_POST['tablename']);
	$filename = $Array_DBTableName[0];
	
	//Find question.
	$sql = "select * from ".$filename." LEFT JOIN sheet ON ".$filename.".table_name = binary(sheet.table_name) 
			WHERE table_number='".$_POST['tablename']."' AND 
			item NOT LIKE '%Base: All Respondents%' AND 
			item NOT LIKE '%Base: Respondents%'";
	
	$result= mysql_query($sql);
	$numResult = mysql_num_rows($result);
			
	if ($numResult > 0) {
?>
<script type='text/javascript'>
	var dataTable = new google.visualization.DataTable();
	var myrow = new Array();
	var objectName = '0:';
	dataTable.addColumn('number');
	<?php
	
		while($row = mysql_fetch_assoc($result)) {
			if ((($row['item']!='')&&
			($row['item']!='Sigma')&&
			($_POST['keyword']==''))||
			//For keyword exists.
			(($row['item']!='')&&
			($row['item']!='Sigma')&&
			($_POST['keyword']!='')&&
			//contain is YES.
			(((strpos($item,(string)$_POST['keyword']))&&
			($_POST['contain']=='YES'))||
			//contain is NO.
			((!strpos($item,(string)$_POST['keyword']))&&
			($_POST['contain']=='NO'))))) {
		?>					
				var value = <?php echo $row['total']; ?>;
				myrow.push([value]);
				
				var TempName = '<?php echo str_replace("'","\'",str_replace('(Net)','',$row['item'])); ?>'.substr(0,4)+'...';
				//var TempName = '<?php echo str_replace("'","\'",str_replace('(Net)','',$row['item'])); ?>'.split(' ')[0]+'...';
				
				objectName = objectName+'|'+TempName;	
		<?php
			}
			else if ($row['item']=='Sigma')
				break;
							
			$item = $row['item'];
		}
		?>
    dataTable.addRows(myrow);
	var options = {	cht:'r', 
					chxt:'x',
					chxl: objectName
				};
				
	
	var chart = new google.visualization.ImageChart(document.getElementById('<?php echo $_POST['season'].$_POST['tablename']; ?>'));
	chart.draw(dataTable, options);
</script>
<?php
	}
?>
<div id='<?php echo $_POST['season'].$_POST['tablename']; ?>' style="width: 100%;"></div>